<template>
  <div class="app-container">
    <el-alert
      title="新建链接"
      type="success"
      effect="dark"
      :closable="false"
    />
    <el-form ref="form" :model="form" label-width="150px" class="form-container">
      <el-form-item label="链接标题">
        <el-input v-model="form.title" />
      </el-form-item>
      <el-form-item label="OPPO账号ID">
        <el-input v-model="form.ownerId" />
      </el-form-item>
      <el-form-item label="OPPO的APIID">
        <el-input v-model="form.oppoApiID" />
      </el-form-item>
      <el-form-item label="OPPOApiKey">
        <el-input v-model="form.oppoApiKey" />
      </el-form-item>
      <el-form-item label="回传比例">
        <el-input v-model="form.paidAmount" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm('form')">立即创建</el-button>
        <el-button @click="onCancel('form')">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { oppoInsertUrl } from '@/api/oppo'
import { getToken } from '@/utils/auth'
import { Message } from 'element-ui'
export default {
  data() {
    return {
      form: {
        title: '',
        ownerId: '',
        oppoApiID: '',
        oppoApiKey: '',
        paidAmount: '',
        mobileNo: getToken()
      }
    }
  },
  methods: {
    async submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          oppoInsertUrl(this.form).then(response => {
            console.log(111)
          }).catch(() => {
            Message({
              message: '访问链接不存在！',
              type: 'error',
              duration: 5 * 1000
            })
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    onCancel() {
      this.$message({
        message: 'cancel!',
        type: 'warning'
      })
    }
  }
}
</script>

<style scoped>
.line{
  text-align: center;
}

.app-container{
  padding: 30px;
}

.form-container{
  margin-top: 20px;
}
</style>

